package com.dyb.recuitment.controller;


import com.dyb.recuitment.common.Result;
import com.dyb.recuitment.entity.Setting;
import com.dyb.recuitment.entity.Shield;
import com.dyb.recuitment.entity.UserLog;
import com.dyb.recuitment.service.IShieldService;
import com.dyb.recuitment.service.IUserLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 屏蔽表 前端控制器
 * </p>
 *
 * @author 邓宇斌
 * @since 2022-02-21
 */
@RestController
@Api(tags = "屏蔽管理(Shield)")
@RequestMapping("/shield")
public class ShieldController {

    @Autowired
    private IShieldService shieldService;

    @Autowired
    private IUserLogService userLogService;

    @ApiOperation(value = "添加屏蔽项", notes = "通过用户ID、公司ID添加屏蔽项" +
            "{\"userId\":1,\"companyId\":1, \"remark\": \"user\"}")
    @ApiImplicitParam(name = "shield", value = "Shield类")
    @PostMapping("/add")
    public Object add(@RequestBody Shield shield) {
        Object data = null;
        try {
            data = shieldService.add(shield);
//            userLogService.add(new UserLog(shield.getUserId(), "添加屏蔽项"));
            if (data == null || (int) data == 0) {
                return Result.warning(data, "当前屏蔽信息已存在!");
            }
            return Result.success(data, "屏蔽成功!");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return Result.failure(data);
    }

    @ApiOperation(value = "删除屏蔽项", notes = "通过ID删除屏蔽项" +
            "{\"id\":1}")
    @ApiImplicitParam(name = "shield", value = "Shield类")
    @PostMapping("/delete")
    public Object delete(@RequestBody Shield shield) {
        Object data = null;
        try {
            data = shieldService.delete(shield);
//            userLogService.add(new UserLog(shield.getUserId(), "删除屏蔽项"));
            if (data == null || data == (Integer) 0) {
                return Result.failure(data, "删除失败!");
            }
            return Result.success(data, "删除成功!");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return Result.failure(data);
    }

    @ApiOperation(value = "查询屏蔽项", notes = "按条件查询屏蔽项 {\"userId\":1,\"remark\":\"user\"}")
    @ApiImplicitParam(name = "shield", value = "Shield类")
    @PostMapping("/selectByShield")
    public Object selectByShield(@RequestBody Shield shield) {
        Object data = null;
        try {
            data = shieldService.selectByShield(shield);
//            userLogService.add(new UserLog(shield.getUserId(), "查询屏蔽项"));
            if (data == null || ((List) data).size() <= 0) {
                return Result.warning(data, "屏蔽项为空!");
            }
            return Result.success(data, "查询成功!");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return Result.failure(data);
    }

    @ApiOperation(value = "查询所有屏蔽项", notes = "查询所有屏蔽项")
    @GetMapping("/selectAllShield")
    public Object selectAllShield() {
        Object data = null;
        try {
            data = shieldService.selectAllShield();
//            userLogService.add(new UserLog(shield.getUserId(), "查询所有屏蔽项"));
            if (data == null || ((List) data).size() <= 0) {
                return Result.warning(data, "屏蔽项为空!");
            }
            return Result.success(data, "查询成功!");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return Result.failure(data);
    }

}
